package cn.qu.phizline;

import com.google.gson.Gson;

import java.nio.charset.Charset;

import cn.qu.phizline.event.Body;
import cn.qu.phizline.event.PayloadConventer;

/**
 * Created by zh on 2017/10/25.
 */

public class AndroidPayloadConventer extends PayloadConventer {
    @Override
    protected byte[] toPayloadBytes(Body body) {
        Gson gson = new Gson();
        String json = gson.toJson(body);
        return json.getBytes(Charset.forName("utf-8"));
    }

    @Override
    protected Body parsePayloadBody(Class<? extends Body> aClass, byte[] bytes) {
        Gson gson = new Gson();
        return gson.fromJson(new String(bytes, Charset.forName("utf-8")), aClass);
    }
}
